home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1.1 / The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso / 6 / c_wndw.zip / WRITTEST.C < prev   
Text File  |  1989-05-25  |  3KB  |  91 lines

  1. /*  (c) Marietta Systems, Inc.  1987
  2. *    All rights reserved
  3. *
  4. *    Test program for filewrit function
  5. *
  6. *    Note: This uses the file created by the test program 'filetest'
  7. */
  8. #include "mtest.h"
  9. int acptlong(long*, enum _JUST, enum ATTRIB, int);
  10. /*  
  11. *
  12. *    Function to accept a long int
  13. *
  14. */
  15. int acptlong(kk, just, atb, digits)
  16. long *kk;
  17. enum _JUST just;
  18. enum ATTRIB atb;
  19. int digits;{
  20.     int z;
  21.     char text[15];
  22. #ifdef LATTICE
  23.     stcl_d(text, *kk);
  24. #else
  25.     ltoa(*kk, text, 10);
  26. #endif
  27.     z = accept(text, just, atb, digits, 0);
  28.     *kk = atol(text);
  29.     return z;
  30.     }
  31. /*  
  32. *
  33. *    Main program
  34. *
  35. */
  36. void main(){
  37. long rec_nbr;
  38. int fh1, fh2, z, x, k;
  39. clr_scrn("Filewrit access test");
  40. KEYMATCH[4] = 0X8000; disp_err("",1); /* activate F8 - AMEND key */
  41. /*
  42. *    open ascii file, and copy it into a relative file with binary
  43. *    length records, stripping the '\n' symbol.
  44. */
  45. fh1 = fileopen("testfile.dat", ascii, readonly);
  46. fh2 = fileopen("testfile.rel", binary, recreate);
  47. if (fh1 <= 0 || fh2 <= 0) goodbye (106);
  48. if (fileinit(fh2, 0, 64, 0L)) goodbye(110);
  49. display ("File opened - records ready to be read", 1, 1, low);   
  50. rec_nbr = 1L;
  51. for (z = 0 , x = 2 ; ; z++, x++){
  52.      if (!(k = fileread(fh1, nextrec, &rec_nbr))) break; /* EOF */
  53.      if (k < 0) goodbye(107); /* read error */
  54.      FN[fh1].record[strlen(FN[fh1].record) - 1] = 0; /* delete '\n' */
  55.      justify (left, FN[fh2].record, FN[fh1].record, 35, 0);
  56.      rec_nbr -= 1L;
  57.      if (filewrit(fh2, &rec_nbr) < 0) goodbye(108);
  58.      display(FN[fh2].record, x, 1, reverse);
  59.      }
  60. if (fileclos(fh1) < 1 || fileclos(fh2) < 1) goodbye(109);
  61. while (!disp_qry(" Ready to random read/write"));
  62. /*
  63. *    reopen file 2
  64. */
  65. fh2 = fileopen("testfile.rel", binary, update);
  66. if (fileinit(fh2, 0, 64, 20L)) goodbye(110);
  67. if (fh2 <= 0) goodbye (106);
  68. display ("File opened - records ready to be read", 1, 40, low); 
  69. display ("Next record number to be actioned", 22, 44, high);
  70. rec_nbr = 1L; 
  71. for (;;){
  72.     if (INCHAR == AMEND) k = fileread(fh2, nextrec, &rec_nbr);
  73.         else k = fileread(fh2, relative, &rec_nbr);
  74.     if (k < 0) goodbye(107); if (!k) break;
  75.     display(FN[fh2].record, 3, 40, reverse);
  76.     set_crsr(22,40);
  77.     rec_nbr -= 1L; 
  78.     z = acptlong(&rec_nbr, code, alt_reverse, 3);
  79.      if (!z) continue;
  80.     if (INCHAR != AMEND) break;
  81.     set_crsr(5, 40);
  82.     if (accept(FN[fh2].record, left, alt_reverse, 35, 0)) 
  83.         if (INCHAR == QUIT) break; else continue;
  84.     filewrit(fh2, &rec_nbr);    
  85.     }
  86. if (fileclos(fh2) < 1) goodbye(109);
  87. disp_msg(" Press any key to end", 1); 
  88. read_kb();
  89. goodbye(0);
  90. }
  91.